package com.itsc.service;

import java.util.ArrayList;
import java.util.List;

import com.itsc.dao.RepairDao;
import com.itsc.entities.Repair;
import com.itsc.service.inter.IRepairService;
import com.itsc.util.page.Page;

public class RepairService implements IRepairService{

	private RepairDao repairDao;
	
	
	public RepairDao getRepairDao() {
		return repairDao;
	}

	public void setRepairDao(RepairDao repairDao) {
		this.repairDao = repairDao;
	}

	public void save(Repair repair) {
		repairDao.save(repair);
	}

	public void delete(Repair repair) {
		repairDao.delete(repair);
	}

	public void update(Repair repair) {
		repairDao.update(repair);
	}

	public Repair selectById(Integer id) {
		String hql = "from Repair where repair_id = ?";
		Repair repair = repairDao.selectById(hql, id);
		return repair;
	}

	public List<Repair> selectAll() {
		List<Repair> repairList = null;
		String hql = "from Repair";
		repairList = repairDao.selectAll(hql);
		return repairList;
	}

	public List<Repair> getAllRepairsByRepairState(String flag)
	{
		List<Repair> waitingRepairList = new ArrayList<Repair>();
		waitingRepairList = repairDao.getAllRepairsByRepairState(flag);
		return waitingRepairList;
	}
	
	public List<Repair> getPageByRepairState(String flag, Page page)
	{
		return repairDao.getPagesByRepairState(flag, page);
	}
	
	public boolean selectByString(String user_phone) {
		
		Repair repair = repairDao.selectByUserPhone(user_phone);
		if(repair != null && !repair.getRepair_state().toString().equals("处理成功")
				&& !repair.getRepair_state().toString().equals("无法解决"))
			return true;
		return false;
	}

	public int getCount() {
		
		return 0;
	}

	public int getCountByRepairState(String repair_sate)
	{
		int count = 0;
		count = repairDao.getCountByRepairState(repair_sate);
		return count;
	}
	
	public List<Repair> getPage(Page page) {
		return null;
	}

	public List<Repair> search(String flag, String searchname, String datemin,
			String datemax, Page page) {
		return repairDao.search(flag, searchname, datemin, datemax, page);
	}

	@Override
	public int getCountByRepairState(String repair_sate, String searchname,
			String datemin, String datemax) {
		// TODO 自动生成的方法存根
		return repairDao.search(repair_sate, searchname, datemin, datemax, null).size();
	}
	

}
